<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="mini" v-show="showSearch" label-width="68px">
      <el-row :gutter="20">
        <el-col :span="3">
          <el-form-item label="姓名" prop="staffName">
            <el-input v-model="queryParams.staffName" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
          </el-form-item>
        </el-col>
        <el-col :span="3">
          <el-form-item label="职务" prop="projectDuitsName">
            <el-select v-model="queryParams.projectDuitsName" placeholder="请选择" clearable
              @keyup.enter.native="handleQuery">
              <el-option v-for="dict in dict.type.cld_project_duits" :key="dict.value" :label="dict.label"
                :value="parseInt(dict.value)"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="3">
          <el-form-item label="岗位" prop="projectPostName">
            <el-select v-model="queryParams.projectPostName" placeholder="请选择" clearable
              @keyup.enter.native="handleQuery">
              <el-option v-for="dict in dict.type.cld_project_post" :key="dict.value" :label="dict.label"
                :value="parseInt(dict.value)"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="3">
          <el-form-item label="清洁性质" prop="cleanNature">
            <el-select v-model="queryParams.cleanNature" placeholder="请选择" clearable @keyup.enter.native="handleQuery">
              <el-option v-for="dict in cleanNatureOptions" :key="dict.value" :label="dict.label"
                :value="parseInt(dict.value)"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="3">
          <el-form-item label="提交状态" prop="approvalStatus">
            <el-select v-model="queryParams.approvalStatus" placeholder="请选择" clearable
              @keyup.enter.native="handleQuery">
              <el-option v-for="dict in workPlanStatusOptions" :key="dict.value" :label="dict.label"
                :value="parseInt(dict.value)"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label-width="10px">
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>

    <el-tabs v-model="workActive" @tab-click="handleWorkActive" >
      <el-tab-pane label="日清洁" name="0">
      </el-tab-pane>
      <el-tab-pane label="专项清洁" name="1">
      </el-tab-pane>
    </el-tabs>

    <el-table v-loading="loading" :data="workPlanList" border>
      <el-table-column label="项目名称" align="center" prop="projectName" width="200px"/>
      <el-table-column label="岗位名称" align="center" prop="projectPostName" width="100px">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.cld_project_post" :value="scope.row.projectPostName" />
        </template>
      </el-table-column>
      <el-table-column label="组别" align="center" prop="groupName" width="100px">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.cld_project_groups" :value="scope.row.groupName" />
        </template>
      </el-table-column>
      <el-table-column label="姓名" align="center" prop="staffName" width="100px"/>
      <el-table-column label="职务" align="center" prop="projectDuitsName" width="100px">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.cld_project_duits" :value="scope.row.projectDuitsName" />
        </template>
      </el-table-column>
      <el-table-column label="工作计划日期" align="center" prop="rowDate" width="120px">
        <template slot-scope="scope">
          {{scope.row.rowDate}}
        </template>
      </el-table-column>
      <el-table-column label="工作时间" align="center" v-if="workActive == 0" width="150px">
        <template slot-scope="scope">
          {{scope.row.startTime}} - {{scope.row.endTime}}
        </template>
      </el-table-column>
      <el-table-column label="时间" align="center" prop="dateType" v-if="workActive == 1" width="80px">
        <template slot-scope="scope">
          <span v-if="scope.row.dateType == 1">周</span>
          <span v-if="scope.row.dateType == 2">月</span>
          <span v-if="scope.row.dateType == 3">季</span>
          <span v-if="scope.row.dateType == 4">年</span>
        </template>
      </el-table-column>
      <el-table-column label="频次" align="center" prop="frequency" v-if="workActive == 1" width="80px">
        <template slot-scope="scope">
          {{scope.row.frequency}}
        </template>
      </el-table-column>
      <el-table-column label="场景" prop="workplanScene" width="150px">
        <template slot-scope="scope">
          <el-tooltip placement="top">
            <div slot="content">{{scope.row.workplanScene}}</div>
            <span>{{ truncatedText(scope.row.workplanScene,8) }}</span>
          </el-tooltip>
        </template>
      </el-table-column>
      <el-table-column label="清洁区域" prop="cleanArea" width="150px">
        <template slot-scope="scope">
          <el-tooltip placement="top">
            <div slot="content">{{scope.row.cleanArea}}</div>
            <span>{{ truncatedText(scope.row.cleanArea,8) }}</span>
          </el-tooltip>
        </template>
      </el-table-column>
      <el-table-column label="工作内容" prop="workplanContent" >
        <template slot-scope="scope">
          <el-tooltip placement="top">
            <div slot="content">{{scope.row.workplanContent}}</div>
            <span>{{ truncatedText(scope.row.workplanContent,65) }}</span>
          </el-tooltip>
        </template>
      </el-table-column>
      <el-table-column label="提交状态" align="center" width="100px">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.approvalStatus == 0" type="info">待提交</el-tag>
          <el-tag v-if="scope.row.approvalStatus != 0" type="success">已提交</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="提交时间" align="center" prop="submitTime" width="160px">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.submitTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="审核状态" align="center" prop="approvalStatus" width="100px">
        <template slot-scope="scope">
          <dict-tag v-if="scope.row.approvalStatus != 0" :options="workPlanStatusOptions" :value="scope.row.approvalStatus" />
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="100px">
        <template slot-scope="scope">
          <el-button size="mini" type="text" v-if="[1].includes(scope.row.approvalStatus)"
            @click="handleFinish(scope.row)" v-hasPermi="['cld:complaints:finish']">确认</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

  </div>
</template>

<script>
import { getWorkPlanDetailsList, auditWorkplan } from "@/api/cld/workplan";
import { cleanNatureOptions, workPlanStatusOptions } from '@/assets/staticDict'
export default {
  name: "Complaints",
  dicts: ['cld_project_post', 'cld_project_groups', 'cld_project_duits'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 工作计划表格数据
      workPlanList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 15,
        projectId: this.$route.params.projectId,
        staffName: null,
        projectDuitsName: null,
        projectPostName: null,
        cleanNature: 1,
        isSubmit: null,
        approvalStatus: null
      },
      // 清洁性质
      cleanNatureOptions: cleanNatureOptions,
      // 确认状态
      workPlanStatusOptions: workPlanStatusOptions,
      // tab切换
      workActive: "0",
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询工作计划列表 */
    getList() {
      this.loading = true;
      getWorkPlanDetailsList(this.queryParams).then(response => {
        this.workPlanList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 切换
    handleWorkActive(e){
      this.workActive = e.index;
      this.queryParams.cleanNature = parseInt(e.index) + 1;
      this.getList();
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 完成
    handleFinish(row) {
      this.$modal.confirm('是否设为客户确认状态？').then(function () {
        let form = {
          workSubmitId: row.workSubmitId,
          approvalStatus: 2
        }
        return auditWorkplan(form);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("操作成功");
      }).catch(() => { });
    },
    truncatedText(val,len) {
      return val.length > len ? `${val.substr(0, len)}...` : val;
    }
  }
};
</script>
<style scoped></style>
